package com.cobra.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

//分区不变原理
object Spark10_RDD_Operator_Transform_GROUP_BY {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Spark10_RDD_Operator_Transform_GROUP_BY")
    val sc = new SparkContext(sparkConf)
    //算子获取
    val rdd = sc.makeRDD(List(1,2,3,4),2)
    def groupFunction(num:Int):Int = {
        num % 2
    }
    val groupRDD = rdd.groupBy(groupFunction(_))
    groupRDD.collect().foreach(println)

    val rdd1 = sc.makeRDD(List("Hello","Spark","Hello","Scala"),2)
    val groupRDD1 = rdd1.groupBy(s => s)
    groupRDD1.collect().foreach(println)
    sc.stop()
  }
}
